package org.anq.ddm.controller;

import com.alibaba.fastjson.JSONObject;
import com.amazonaws.services.s3.model.ObjectMetadata;
import org.anq.ddm.pojo.*;
import org.anq.ddm.service.*;
import org.anq.ddm.utils.AwzS3Util;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
public class TestController {

    @Autowired
    FormService formService;

    @Autowired
    CamundaService camundaService;

    @Autowired
    InstanceService instanceService;

    @Autowired
    BpmnProcessService processInfoService;

    @Autowired
    private MongoTemplate mongoTemplate;






    /**
     * 展示当前任务所需要的表单。
     * 目前仅支持单线任务。
     *
     * @return

    @RequestMapping(value = "/showTasks/{instanceId}", method = RequestMethod.GET)
    public Map<String,Object> showTasks(@PathVariable String instanceId) {
        Map<String,Object> map = new HashMap<>();
            List<String> tasks = this.camundaService.queryTaskIdByInstanceId(instanceId);
            if (tasks != null) {
                String formKey = this.camundaService.getFormKey(tasks.get(0));
                map.put("formId",formKey);
                map.put("data",this.formService.getById(Integer.parseInt(formKey)).getFormvalue());
                map.put("taskId",tasks.get(0));


                List<FormValue> fvList = this.formValueService.findByInstanceId(instanceId);
                if(fvList!=null){
                    Map<String,Object> cvmap = new HashMap<>();
                    for(FormValue fv : fvList){
                        cvmap.put(fv.getContentkey(),fv.getContentvalue());
                    }
                    map.put("contentValue",cvmap);
                }
                return map;
            } else {
                return null;
            }
    }
     */






    /**
     * 老方法，不使用mongodb，且方法已过期
     * 待办
     * 该处的instanceid应为definitionkey
     * @return

    @RequestMapping(value = "/applyListData/{definationKey}", method = RequestMethod.GET)
    public List<Map<String,Object>> applyListData(@PathVariable String definationKey){

        List<Task> taskList = this.camundaService.queryAllTask(definationKey);
        List<Map<String,Object>> list = new ArrayList<>();

        if(taskList!=null){
            for(Task t:taskList){
                List<FormValue> fvList = this.formValueService.findByInstanceId(t.getInstanceId());
                if(fvList!=null){
                    Map<String,Object> cvmap = new HashMap<>();
                    cvmap.put("instanceid",t.getInstanceId());
                    for(FormValue fv : fvList){
                        cvmap.put(fv.getContentkey(),fv.getContentvalue());
                    }
                    list.add(cvmap);
                }
            }
        }
        return list;
    }
     */














}
